/**
 * Created by Administrator on 2017/10/24
 */
import * as mobx from 'mobx';
import { ListStore } from './listStore';
import { WeaForm } from 'comsMobx';
import * as WORKFLOW_AGENt from '../apis/agent';

const { observable, action } = mobx;

export class WFDealRepetitionStore extends ListStore {

    @observable dealRepetiVisible = false;
    highSearchInitDate = {};
    ids = '';

    constructor () {
        super();
        this.setVisible = this.setVisible.bind(this);
        this.setConditionByTree = this.setConditionByTree.bind(this);
        this.doSearch = this.doSearch.bind(this);
        this.reload = this.reload.bind(this);
    }

    @action

    initDatas () {
        WORKFLOW_AGENt.getWfHighSearch({agented:0,agentFlag:1,belongOverlap:true}).then((datas)=>{
            this.condition = datas.condition;
            this.form && !this.form.isFormInit && this.form.initFormFields(datas.condition);
            this.highSearchInitDate = datas.formValue;
            this.form.updateFields(datas.formValue,false);
        })
    }

    doSearch (params = '') {
        const overlapIds = this.ids;
        const searchParamsAd = this.form.getFormParams();
        WORKFLOW_AGENt.getWfAgentList({...searchParamsAd,agented:0,agentFlag:1,belongOverlap:true,overlapIds}).then((datas)=>{
            const { sessionkey } = datas;
            this.tableStore.getDatas(sessionkey, params.current || 1);
        });
    }

    setVisible (visible = false,params = '') {
        if(!visible){
            this.dealRepetiVisible = false;
            this.resetTable();
        }else{
            this.ids = params;
            WORKFLOW_AGENt.getWfAgentList({agented:0,agentFlag:1,belongOverlap:true,overlapIds:params}).then((datas)=>{
                const { sessionkey } = datas;
                this.tableStore.getDatas(sessionkey, params.current || 1);
                this.dealRepetiVisible = true;
            });
        }
    }

    setConditionByTree () {
        return 0;
    }

    reload () {
        const current = this.tableStore.current;
        this.doSearch({current});
    }
    clearFormFields(){
        this.form.resetConditionValue();      //清除查询条件值
        this.form.updateFields(this.highSearchInitDate,false);
    }
    clearStatus () {
        this.clearFormFields();
    }

}